{% extends "forum/base.html" %}
{% load i18n %}

{% block extra-staff-menu %}
    : <a title='{% trans "Edit forum"%}' href='{% url admin:forum_forum_change forum.id %}'>{% trans "Edit" %}</a>
{% endblock %}

{% block body %}

{% include "forum/includes/forum_image.html" %}

{% include "forum/includes/parent_bar.html" %}

{% if forum.subforuns.count %}
<hr />
<div class="space">
    <table class="foruns">
        <thead>
            <tr>
                <th class="span-1 forumcell-name">
                    {% trans "Sub-Forum" %}</th>
                <th class="span-1 forumcell-topics">
                    {% trans "Topics" %}</th>
                <th class="span-1 forumcell-posts">
                    {% trans "Posts" %}</th>
                <th class="span-1 forumcell-lastpost last">
                    {% trans "Last Post" %}</th>
            </tr>
        </thead>
        <tbody>
            {% for subforum in forum.subforuns.all %}
            <tr {% if forloop.counter|divisibleby:2 %} class="mark" {% endif %}>
                <td class="forumcell-name">
                    <div class="clearfix">
                        <a href='{{ subforum.link }}'>{{subforum}}</a></div>
                    <div class="clear small" style="margin-bottom: 0px;">
                        <span class="quiet">{{subforum.short}}</span></div>
                </td>
                <td class="forumcell-topics">{{subforum.topic_count}}</td>
                <td class="forumcell-posts">{{subforum.reply_count}}</td>
                <td class="forumcell-lastpost last">
                    {% if subforum.topic_count %}
                    {% with subforum.last_topic as last_topic %}
                        <a href='{{ subforum.link.last_topic }}'>{{last_topic|capfirst}}</a><br />
                         by <a href='{% url forum-user-profile last_topic.username,"view" %}'>{{last_topic.username}}</a>
                        at {{last_topic.created|date}}
                    {% endwith %}
                    {% else %}
                    <span>{% trans "No posts" %}</span>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}
{# IF forum.subforuns.count #}
<hr />

{% if forum.allow_topics %}
<div class="space">
    <div id="forum_bar" class="clearfix">
        <a class="button"
            href="{{ forum.link.post }}"
            title='{% trans "Create new topic?" %}'>{% trans "New topic" %}</a>
    </div>
</div>
{% endif %}

<div class="space clearfix">
{% if page %}
{% if page.paginator.count %}
    {% include "forum/includes/digg_paginator.html" %}
    <table class="forum">
        <caption><b>{% trans "Topics from" %}</b> : {{forum.title}}</caption>
        <thead>
            {# header with topic summary, answers count, views count and last answer summary #}
            <tr>
                <th class="forumcell-image span-1"></th>
                <th class="forumcell-name span-1">{% trans "Topic" %}</th>
                <th class="forumcell-answers span-1">{% trans "Answers" %}</th>
                <th class="forumcell-views span-1">{% trans "Views" %}</th>
                <th class="forumcell-lastpost span-1 last">{% trans "Last Post" %}</th>
            </tr>
        </thead>

        <tbody>
            {% for topic in page.object_list %}
            <tr id="{{topic.html_id}}" {% if forloop.counter|divisibleby:2 %} class="mark" {% endif %}>
                <td class="forumcell-image">
                    <img alt='{% trans "Topic status image"%}' src="{{topic.get_status_image}}"></img>
                </td>
                <td class="forumcell-name">
                    <div class="clearfix">
                        <div class="span-1 last" style="width:100%; overflow: hidden;">
                            {% if not topic.active %}{% trans "Inactive" %} : {% endif %}
                            {% if topic.fixed %}{% trans "Sticky" %} : {% endif %}
                            {% if topic.closed %}{% trans "Closed" %} : {% endif %}
                            <a href='{{topic.link}}'>{{topic.title}}</a>
                        </div>
                    </div>
                    <div class="clear">
                        <span class="quiet small">
                            <a style="text-decoration: none" 
                            href='{% url forum-user-profile topic.username %}'>{{topic.username}}</a>
                            {% if topic.short %}- {{topic.short|capfirst|truncatewords:5}}{% endif %}
                        </span>
                    </div>
                </td>
                <td class="forumcell-answers">
                    {{topic.reply_count}}
                </td>
                <td class="forumcell-views">
                    {{topic.views_count}}
                </td>
                {# last topic #}
                <td class="forumcell-lastpost">
                    {% with topic.latest_reply as latest_reply %}
                    <span title='{% trans "Would you kindly help this poor soul?" %}'>
                        {% if latest_reply %}
                            {{latest_reply.created_time|date}} {% trans "by"%} <a href='{% url forum-user-profile latest_reply.username %}'>{{latest_reply.author}}</a>
                        {% else %}
                            {% trans "No posts" %}
                        {% endif %}
                    </span>
                    {% endwith %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    {% include "forum/includes/digg_paginator.html" %}

{% else %}
    <div class="notice" style="margin-top: 10px;">{% trans "There are no topics registered within this forum. Would you mind writing one? = ]" %}</div>
{% endif %} {# IF page.paginator.count #}
{% endif %} {# IF page #}

</div>

{% if forum.allow_topics %}
<div class="space">
    <div id="forum_bar" class="clearfix">
        <a class="button"
            href="{{forum.link.post}}"
            title='{% trans "Create new topic?" %}'>{% trans "New topic" %}</a>
    </div>
</div>
{% endif %}

<br />
<fieldset class="space">
     <dl>
         <dt>{% trans "Moderation" %}</dt>
         <dd>
         {% if forum.moderation.all.count %}
             {% for m_user in forum.moderation.all %}
             <a href="{{m_user.frm_profile.link}}">{{m_user}}</a>
             {% endfor %}
         {% else %}
         {% trans "This forum does not have moderation." %}
         {% endif %}
         </dd>
     </dl>
</fieldset>

{# ends topics.count #}

{% endblock body %}
